use axum::{body::Body, extract::State, http::Response, response::IntoResponse};
use redis::AsyncCommands;
use sky_common::constant;

use crate::{bootstrap::AppState, router::resp::RespVO};

pub async fn get_shop_status(State(mut state): State<AppState>) -> Response<Body> {
    match state
        .redis
        .get(constant::shop::SHOP_STATUS_KEY.to_string())
        .await
    {
        Ok(status) => {
            let info = if status == 1 {
                constant::shop::SHOP_STATUS_1
            } else {
                constant::shop::SHOP_STATUS_0
            };
            let status_info = format!("获取到店铺的营业状态为：{}", info);

            tracing::info!(status_info);

            RespVO::<i32>::success(status_info.to_owned(), Some(status)).into_response()
        }
        Err(e) => RespVO::<String>::error("设置店铺状态失败".to_owned(), Some(e.to_string()))
            .into_response(),
    }
}
